package cn.guet.spider.ctrip.task;

import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Component;

import cn.guet.base.spider.BaseTask;
import cn.guet.base.spider.http.HttpClientUtil;
import cn.guet.spider.ctrip.entity.Hotel;
import cn.guet.spider.ctrip.service.IHotelService;
import cn.guet.spider.ctrip.task.parser.HotelParser;

/**
 * 携程爬虫任务，目前只有酒店
 *
 * @author SAGITTAR
 */
@Component(value = "hotelTask")
public class HotelTask extends BaseTask<IHotelService, Hotel, HotelParser> {

	private static final String TRIP_URL = "http://hotels.ctrip.com/hotel/%s/%s";

	public void execute() throws Exception {
		String html = HttpClientUtil.getWebPage(String.format(TRIP_URL, "guilin33", "p1"));
		Elements elements = Jsoup.parse(html).select(".hotel_new_list");
		List<Hotel> tripHotelList = parser.parse(elements);
		// baseService.insertBatch(tripHotelList);
		tripHotelList.forEach(hotel -> logger.info(hotel));
		parser.release();
	}
}
